<?php

// +----------------------------------------------------------------------

// | Fanwe 多语商城建站系统 (Build on ThinkPHP)

// +----------------------------------------------------------------------

// | Copyright (c) 2009 http://www.fanwe.com All rights reserved.

// +----------------------------------------------------------------------

// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )

// +----------------------------------------------------------------------

// | Author: 云淡风轻(97139915@qq.com)

// +----------------------------------------------------------------------

if (! defined('THINK_PATH'))

	exit();

//由数据库取出系统的配置
function fanweC($name)
{
	static $sysConf = NULL;
	
	if($name == 'SHOP_URL')
		return "http://".$_SERVER['HTTP_HOST'];
	else
	{
		if ($sysConf === NULL)
		{
			$sysConf = D("SysConf")->where("status=1")->getField("name,val");
		}
		
		return $sysConf[$name];
	}
}

//全站通用的清除所有缓存的方法
function clear_cache ()
{
	Dir::delDir(getcwd() . "/admin/Runtime/Cache/");
	Dir::delDir(getcwd() . "/admin/Runtime/Data/");
	Dir::delDir(getcwd() . "/admin/Runtime/Temp/");
	@unlink(getcwd() . "/admin/Runtime/~app.php");
	@unlink(getcwd() . "/admin/Runtime/~runtime.php");
	Dir::delDir(getcwd() . "/app/Runtime/Cache/");
	Dir::delDir(getcwd() . "/app/Runtime/Data/");
	Dir::delDir(getcwd() . "/app/Runtime/Temp/");
	Dir::delDir(getcwd() . "/app/Runtime/Html/");
	@unlink(getcwd() . "/app/Runtime/~app.php");
	@unlink(getcwd() . "/app/Runtime/~runtime.php");
	Dir::delDir(getcwd() . "/install/Runtime/Cache/");
	Dir::delDir(getcwd() . "/install/Runtime/Data/");
	Dir::delDir(getcwd() . "/install/Runtime/Temp/");
	@unlink(getcwd() . "/install/Runtime/~app.php");
	@unlink(getcwd() . "/install/Runtime/~runtime.php");
	
	//Vendor('cachehandler');
	//CacheManage::getInstance()->clear(FANWE_ROOT.'./caches');
}

//过滤请求
function filter_request (&$request)
{
	if (MAGIC_QUOTES_GPC)
	{
		foreach ($request as $k => $v)
		{
			if (is_array($v))
			{
				filter_request($v);
			}
			else
			{
				$request[$k] = stripslashes($v);
			}
		}
	}
}

/**
 * 获得当前格林威治时间的时间戳
 *
 * @return  integer
 */
function gmtTime ()
{
	return (time() - date('Z'));
}

function toDate ($time, $format = 'Y-m-d H:i:s')
{
	if (empty($time))
	{
		return '';
	}
	$timezone = intval(fanweC('TIME_ZONE'));
	$time = $time + $timezone * 3600;
	$format = str_replace('#', ':', $format);
	return date($format, $time);
}

/**
 *  将一个用户自定义时区的日期转为GMT时间戳
 *
 * @access  public
 * @param   string      $str
 *
 * @return  integer
 */
function localStrToTime ($str)
{
	$str = trim($str);
	if(empty($str))
		return 0;
	$timezone = intval(fanweC('TIME_ZONE'));
	$time = strtotime($str) - $timezone * 3600;
	return $time;
}

function parseUrl($url)
{
	$parse_url = parse_url($url);
	return (!empty($parse_url['scheme']) && !empty($parse_url['host']));
}

function getUri()
{
	if (isset($_SERVER['REQUEST_URI'])) 
		$uri = $_SERVER['REQUEST_URI'];  
	else 
	{ 
		if (isset($_SERVER['argv'])) 
			$uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['argv'][0]; 
		else 
			$uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING']; 
	} 
	return $uri; 
} 

function get_all_files ($path)
{
	$list = array();
	foreach (glob($path . '/*') as $item)
	{
		if (is_dir($item))
		{
			$list = array_merge($list, get_all_files($item));
		}
		else
		{
			//if(eregi(".php",$item)){}//这里可以增加判断文件名或其他。changed by:edlongren
			$list[] = $item;
		}
	}
	return $list;
}

function checkAuthorization()
{

}



function getTabeSize ($a, $b)

{
	return byte_format($a + $b);
}



function byte_format ($size, $dec = 2)
{
	$a = array("B" , "KB" , "MB" , "GB" , "TB" , "PB");

	$pos = 0;

	while ($size >= 1024)

	{

		$size /= 1024;

		$pos ++;

	}

	return round($size, $dec) . " " . $a[$pos];

}



//公共函数

function sysConfL ($key)

{

	if (preg_match("/TITLE_DEFAULT_LANG_/", $key, $res))

	{

		$key = str_replace("TITLE_DEFAULT_LANG_", "", $key);

		return $key;

	}

	return L($key);

}



function userGroupName ($group_id)

{

	return D("UserGroup")->where("id=" . $group_id)->getField("name_" . DEFAULT_LANG_ID);

}



function getCityName ($city_id)

{

	return M("GroupCity")->where("id=" . $city_id)->getField('name');

}



function get_client_ip ()

{

	if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))

		$ip = getenv("HTTP_CLIENT_IP");

	else 

		if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))

			$ip = getenv("HTTP_X_FORWARDED_FOR");

		else 

			if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))

				$ip = getenv("REMOTE_ADDR");

			else 

				if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))

					$ip = $_SERVER['REMOTE_ADDR'];

				else

					$ip = "unknown";

	return ($ip);

}



// 缓存文件

function cmssavecache ($name = '', $fields = '')

{

	$Model = D($name);

	$list = $Model->select();

	$data = array();

	foreach ($list as $key => $val)

	{

		if (empty($fields))

		{

			$data[$val[$Model->getPk()]] = $val;

		}

		else

		{

			// 获取需要的字段

			if (is_string($fields))

			{

				$fields = explode(',', $fields);

			}

			if (count($fields) == 1)

			{

				$data[$val[$Model->getPk()]] = $val[$fields[0]];

			}

			else

			{

				foreach ($fields as $field)

				{

					$data[$val[$Model->getPk()]][] = $val[$field];

				}

			}

		}

	}

	$savefile = cmsgetcache($name);

	// 所有参数统一为大写

	$content = "<?php\nreturn " . var_export(array_change_key_case($data, CASE_UPPER), true) . ";\n?>";

	file_put_contents($savefile, $content);

}



function cmsgetcache ($name = '')

{

	return DATA_PATH . '~' . strtolower($name) . '.php';

}



function getStatus ($status, $imageShow = true)

{

	switch ($status)

	{

		case 0:

			$showText = L("FORBID");

			$showImg = '<IMG SRC="' . APP_TMPL_PATH . '/ThemeFiles/Images/locked.gif" WIDTH="20" HEIGHT="20" BORDER="0" ALT="' . L("FORBID") . '">';

			break;

		case 1:

			$showText = L("NORMAL");

			$showImg = '<IMG SRC="' . APP_TMPL_PATH . '/ThemeFiles/Images/ok.gif" WIDTH="20" HEIGHT="20" BORDER="0" ALT="' . L("NORMAL") . '">';

			break;

	}

	return ($imageShow === true) ? $showImg : $showText;

}



function getBest($isBest, $imageShow = true)

{

	switch ($isBest)

	{

		case 0:

			$showText = "未推荐";

			$showImg = '<IMG SRC="' . APP_TMPL_PATH . '/ThemeFiles/Images/locked.gif" WIDTH="20" HEIGHT="20" BORDER="0" ALT="' . $showText . '">';

			break;

		case 1:

			$showText = "已推荐";

			$showImg = '<IMG SRC="' . APP_TMPL_PATH . '/ThemeFiles/Images/ok.gif" WIDTH="20" HEIGHT="20" BORDER="0" ALT="' . $showText . '">';

			break;

	}

	return ($imageShow === true) ? $showImg : $showText;

}



function getHot($isHot, $imageShow = true)

{

	switch ($isHot)

	{

		case 0:

			$showText = "非热销";

			$showImg = '<IMG SRC="' . APP_TMPL_PATH . '/ThemeFiles/Images/locked.gif" WIDTH="20" HEIGHT="20" BORDER="0" ALT="' . $showText . '">';

			break;

		case 1:

			$showText = "热销";

			$showImg = '<IMG SRC="' . APP_TMPL_PATH . '/ThemeFiles/Images/ok.gif" WIDTH="20" HEIGHT="20" BORDER="0" ALT="' . $showText . '">';

			break;

	}

	return ($imageShow === true) ? $showImg : $showText;

}



function getAuth($isAuth, $imageShow = true)

{

	switch ($isAuth)

	{

		case 0:

			$showText = "未认证";

			$showImg = '<IMG SRC="' . APP_TMPL_PATH . '/ThemeFiles/Images/locked.gif" WIDTH="20" HEIGHT="20" BORDER="0" ALT="' . $showText . '">';

			break;

		case 1:

			$showText = "已认证";

			$showImg = '<IMG SRC="' . APP_TMPL_PATH . '/ThemeFiles/Images/ok.gif" WIDTH="20" HEIGHT="20" BORDER="0" ALT="' . $showText . '">';

			break;

	}

	return ($imageShow === true) ? $showImg : $showText;

}





function getDefaultStyle ($style)

{

	if (empty($style))

	{

		return 'blue';

	}

	else

	{

		return $style;

	}

}



function IP ($ip = '', $file = 'UTFWry.dat')

{

	$_ip = array();

	if (isset($_ip[$ip]))

	{

		return $_ip[$ip];

	}

	else

	{

		import("ORG.Net.IpLocation");

		$iplocation = new IpLocation($file);

		$location = $iplocation->getlocation($ip);

		$_ip[$ip] = $location['country'] . $location['area'];

	}

	return $_ip[$ip];

}



function getNodeName ($id)

{

	if (Session::is_set('nodeNameList'))

	{

		$name = Session::get('nodeNameList');

		return $name[$id];

	}

	$Group = D("Node");

	$list = $Group->getField('id,name');

	$name = $list[$id];

	Session::set('nodeNameList', $list);

	return $name;

}



function showStatus2($status, $id)

{

	switch ($status)

	{

		case 0:

			$info = '<a href="javascript:resume(' . $id . ')">审核</a>';

			break;

		case 2:

			$info = '<a href="javascript:pass(' . $id . ')">' . L("PASS") . '</a>';

			break;

		case 1:

			$info = '<a href="javascript:forbid(' . $id . ')">取消审核</a>';

			break;

		case - 1:

			$info = '<a href="javascript:recycle(' . $id . ')">' . L("RECYCLE") . '</a>';

			break;

	}

	return $info;

}



function showStatus ($status, $id)

{

	switch ($status)

	{

		case 0:

			$info = '<a href="javascript:resume(' . $id . ')">' . L("RESUME") . '</a>';

			break;

		case 2:

			$info = '<a href="javascript:pass(' . $id . ')">' . L("PASS") . '</a>';

			break;

		case 1:

			$info = '<a href="javascript:forbid(' . $id . ')">' . L("FORBID") . '</a>';

			break;

		case - 1:

			$info = '<a href="javascript:recycle(' . $id . ')">' . L("RECYCLE") . '</a>';

			break;

	}

	return $info;

}



function showStatusJq ($status, $id)

{

	switch ($status)

	{

		case 0:

			$info = '<a href="javascript:resumeJq(' . $id . ')">' . L("RESUME") . '</a>';

			break;

		case 2:

			$info = '<a href="javascript:passJq(' . $id . ')">' . L("PASS") . '</a>';

			break;

		case 1:

			$info = '<a href="javascript:forbidJq(' . $id . ')">' . L("FORBID") . '</a>';

			break;

		case - 1:

			$info = '<a href="javascript:recycleJq(' . $id . ')">' . L("RECYCLE") . '</a>';

			break;

	}

	return $info;

}



function getInputType ($status)

{

	switch ($status)

	{

		case 0:

			$info = L("INPUT_TYPE_0");

			break;

		case 1:

			$info = L("INPUT_TYPE_1");

			break;

	}

	return $info;

}



/**

 +----------------------------------------------------------

 * 获取登录验证码 默认为4位数字

 +----------------------------------------------------------

 * @param string $fmode 文件名

 +----------------------------------------------------------

 * @return string

 +----------------------------------------------------------

 */

function build_verify ($length = 4, $mode = 1)

{

	return rand_string($length, $mode);

}



function sort_by ($array, $keyname = null, $sortby = 'asc')

{

	$myarray = $inarray = array();

	# First store the keyvalues in a seperate array

	foreach ($array as $i => $befree)

	{

		$myarray[$i] = $array[$i][$keyname];

	}

	# Sort the new array by

	switch ($sortby)

	{

		case 'asc':

			# Sort an array and maintain index association...

			asort($myarray);

			break;

		case 'desc':

		case 'arsort':

			# Sort an array in reverse order and maintain index association

			arsort($myarray);

			break;

		case 'natcasesor':

			# Sort an array using a case insensitive "natural order" algorithm

			natcasesort($myarray);

			break;

	}

	# Rebuild the old array

	foreach ($myarray as $key => $befree)

	{

		$inarray[] = $array[$key];

	}

	return $inarray;

}



/**

	 +----------------------------------------------------------

 * 产生随机字串，可用来自动生成密码

 * 默认长度6位 字母和数字混合 支持中文

	 +----------------------------------------------------------

 * @param string $len 长度

 * @param string $type 字串类型

 * 0 字母 1 数字 其它 混合

 * @param string $addChars 额外字符

	 +----------------------------------------------------------

 * @return string

	 +----------------------------------------------------------

 */

function rand_string ($len = 6, $type = '', $addChars = '')

{

	$str = '';

	switch ($type)

	{

		case 0:

			$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' . $addChars;

			break;

		case 1:

			$chars = str_repeat('0123456789', 3);

			break;

		case 2:

			$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . $addChars;

			break;

		case 3:

			$chars = 'abcdefghijklmnopqrstuvwxyz' . $addChars;

			break;

		default:

			// 默认去掉了容易混淆的字符oOLl和数字01，要添加请使用addChars参数

			$chars = 'ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789' . $addChars;

			break;

	}

	if ($len > 10)

	{ //位数过长重复字符串一定次数

		$chars = $type == 1 ? str_repeat($chars, $len) : str_repeat($chars, 5);

	}

	if ($type != 4)

	{

		$chars = str_shuffle($chars);

		$str = substr($chars, 0, $len);

	}

	else

	{

		// 中文随机字

		for ($i = 0; $i < $len; $i ++)

		{

			$str .= msubstr($chars, floor(mt_rand(0, mb_strlen($chars, 'utf-8') - 1)), 1);

		}

	}

	return $str;

}



function pwdHash ($password, $type = 'md5')

{

	return hash($type, $password);

}



function checkUrl ($url)

{

	if (strtolower(substr($url, 0, 7)) == "http://")

		return TRUE;

	else

		return false;

}



function gtZero ($id)

{

	return $id > 0;

}





/**

 * 将日期数字 返回成日期格式

 *

 * @param unknown_type $str

 * @return unknown

 */

function timeToLocalStr ($time, $format = 'Y-m-d H:i:s')

{

	return toDate($time, $format);

}



function checkDateFormat ($dateStr)

{

	if (preg_match("/\b\d{4}-\d{2}-\d{2}\b/i", $dateStr) == 1)

		return true;

	else

		return false;

}



function parseToTimeSpan ($dateStr)

{

	if ($dateStr)

	{

		$dataArr = explode("-", $dateStr);

		return mktime(0, 0, 0, intval($dataArr[1]), intval($dataArr[2]), intval($dataArr[0]));

	}

	else

	{

		return 0;

	}

}



function parseToTimeSpanFull ($dateStr)

{

	if ($dateStr)

	{

		$arr = explode(" ", $dateStr);

		$dataArr = explode("-", $arr[0]);

		$timeArr = explode(":", $arr[1]);

		return mktime(intval($timeArr[0]), intval($timeArr[1]), intval($timeArr[2]), intval($dataArr[1]), intval($dataArr[2]), intval($dataArr[0]));

	}

	else

	{

		return 0;

	}

}



function getArticleCateType ($type)

{

	switch ($type)

	{

		case '0':

			return L("ARTICLE_CATE_TYPE_0");

		case '1':

			return L("ARTICLE_CATE_TYPE_1");

		case '2':

			return L("ARTICLE_CATE_TYPE_2");

		case '3':

			return L("ARTICLE_CATE_TYPE_3");

		case '4':

			return L("ARTICLE_CATE_TYPE_4");

	}

}



function checkDiscount ($discount)

{

	if ($discount <= 0 || $discount > 1)

	{

		return false;

	}

	else

		return true;

}



function priceFormat ($num)

{

	return fanweC("BASE_CURRENCY_UNIT") . number_format(round($num, 2), 2);

}



function priceVal ($num)

{

	return str_replace(",", "", number_format(round($num, 2), 2));

}



function getRegionName ($arr)

{

	return $arr['name'];

}



function getNavType ($type)

{

	switch ($type)

	{

		case '1':

			return L('NAV_TYPE_1');

		case '2':

			return L('NAV_TYPE_2');

		case '3':

			return L('NAV_TYPE_3');

	}

}



function getLinkType ($type)

{

	switch ($type)

	{

		case '1':

			return L('LINK_TYPE_1');

		case '2':

			return L('LINK_TYPE_2');

		case '0':

			return L('LINK_TYPE_0');

	}

}



function getLogResult ($rs)

{

	if ($rs == 1)

		return L('LOG_SUCCESS');

	else

		return L('LOG_FAILED');

}



function getLang ($var)

{

	return L("LOG_" . $var);

}



function getAuthType ($type)

{

	switch ($type)

	{

		case '1':

			return L('AUTH_TYPE_1');

		case '2':

			return L('AUTH_TYPE_2');

		case '0':

			return L('AUTH_TYPE_0');

	}

}



function getNode ($arr, $field)

{

	if ($field == "auth_type")

	{

		return getAuthType($arr[$field]);

	}

	else

		return $arr[$field];

}



function getAdvType ($type)

{

	switch ($type)

	{

		case '1':

			return L('ADV_TYPE_1');

		case '2':

			return L('ADV_TYPE_2');

		case '3':

			return L('ADV_TYPE_3');

	}

}



function getUserName ($user_id)

{

	if (D("User")->where("id=" . $user_id)->getField("user_name"))

	{

		return D("User")->where("id=" . $user_id)->getField("user_name");

	}

	else

	{

		return L("NO_USER");

	}

}



function check_mail ($mail)

{

	if (! preg_match("/\w+@\w+\.\w{2,}\b/", $mail))

	{

		return false;

	}

	else

	{

		return true;

	}

}



function check_time ($timestr)

{

	if (preg_match("/\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}/", $timestr))

	{

		return true;

	}

	else

	{

		return false;

	}

}



function getSort ($sort, $goods_id)

{

	$str = "<span onclick='changeSort(this," . $goods_id . ")' title='" . L("CLICK_TO_CHANGE") . "'>" . $sort . "</span>";

	return $str;

}



function unescape ($str, $charcode = "")

{

	$text = preg_replace_callback("/%u[0-9A-Za-z]{4}/", "toUtf8", $str);

	if (empty($charcode))

	{

		return $text;

	}

	else

	{

		return mb_convert_encoding($text, $charcode, "utf-8");

	}

}



function toUtf8 ($ar)

{

	$c = "";

	foreach ($ar as $val)

	{

		$val = intval(substr($val, 2), 16);

		if ($val < 0x7F)

		{ // 0000-007F

			$c .= chr($val);

		}

		elseif ($val < 0x800)

		{ // 0080-0800

			$c .= chr(0xC0 | ($val / 64));

			$c .= chr(0x80 | ($val % 64));

		}

		else

		{ // 0800-FFFF

			$c .= chr(0xE0 | (($val / 64) / 64));

			$c .= chr(0x80 | (($val / 64) % 64));

			$c .= chr(0x80 | ($val % 64));

		}

	}

	return $c;

}



function showNavStatus ($status, $id)

{

	if (D("Nav")->where("id=" . $id)->getField("is_fix") == 0)

	{

		switch ($status)

		{

			case 0:

				$info = '<a href="javascript:resume(' . $id . ')">' . L("RESUME") . '</a>';

				break;

			case 2:

				$info = '<a href="javascript:pass(' . $id . ')">' . L("PASS") . '</a>';

				break;

			case 1:

				$info = '<a href="javascript:forbid(' . $id . ')">' . L("FORBID") . '</a>';

				break;

			case - 1:

				$info = '<a href="javascript:recycle(' . $id . ')">' . L("RECYCLE") . '</a>';

				break;

		}

		

		return $info;

	}

	else

	{

		switch ($status)

		{

			case 0:

				$info = '<a href="javascript:resume(' . $id . ')">' . L("RESUME") . '</a>';

				break;

			case 1:

				$info = '<a href="javascript:forbid(' . $id . ')">' . L("FORBID") . '</a>';

				break;

		}

		

		return $info;

	}

}

function showCityLink($is_fix,$id)
{
	if($is_fix == 0)
	{
		$link .= '&nbsp;<a href="javascript:foreverdel(' . $id . ')">' . L("DELETE") . '</a>';
	}
	else
	{
		$link =  '';
	}

	return $link;
}



function showNavDel ($id)

{

	if (D("Nav")->where("id=" . $id)->getField("is_fix") == 0)

	{

		$info = '<a href="javascript:foreverdel(' . $id . ')">' . L("DELETE") . '</a>';

		return $info;

	}

	else

	{

		return '';

	}

}



function getAdmName ($id)

{

	return M("Admin")->where("id=" . $id)->getField("adm_name");

}



function getHiddenBox ($id)

{

	return $id . "<input type='hidden' name='hiddenid[]' value='" . $id . "' />";

}



function formatPrice ($price, $radio)

{

	$currency_item = Session::get("fanwe_currency");

	if ($radio != null)

	{

		$price = $price * $radio;

	}

	else

	{

		$price = $price * $currency_item['radio'];

	}

	$price = number_format(round($price, 2), 2);

	//$currency_item['unit'].

	$price = "¥" . $price;

	return $price;

}



function checkArticleUName ($uname)

{

	$id = intval($_REQUEST['id']);

	if (M("Article")->where("u_name='" . $uname . "' and id <> $id")->count() == 0)

	{

		return true;

	}

	else

		return false;

}



function checkGoodsUName ($uname)

{

	$id = intval($_REQUEST['id']);

	if (M("Goods")->where("u_name='" . $uname . "' and id <> $id")->count() == 0)

	{

		return true;

	}

	else

		return false;

}



function get_role_name ($id)

{

	$admin = M("Admin")->getById($id);

	if ($admin['adm_name'] == fanweC("SYS_ADMIN"))

	{

		return "<span style='color:#f30;'>默认管理员</span>";

	}

	else

		return M("Role")->where("id=" . $admin['role_id'])->getField("name");

}

/**
 * 初始化会员数据整合类
 *
 * @access  public
 * @return  object
 */
function &init_users()
{
    static $cls = null;
    if ($cls != null)
    {
        return $cls;
    }
	
	$code = fanweC('INTEGRATE_CODE');
    Vendor('integrates.'.$code);
    $cfg = unserialize(fanweC('INTEGRATE_CONFIG'));
    $cls = new $code($cfg);

    return $cls;
}

function utf8ToGB($str)
{
	static $chinese = NULL;
	if($chinese === NULL)
	{
		Vendor("chinese");
		$chinese = new Chinese('UTF-8','GBK');
	}
	return $chinese->convert($str);
}

function gbToUTF8($str)
{
	static $chinese = NULL;
	if($chinese === NULL)
	{
		Vendor("chinese");
		$chinese = new Chinese('GBK','UTF-8');
	}
	return $chinese->convert($str);
}

function setBaseMoney($money,$currency_id)
{
	return $money;
}
function getBaseMoney($money,$currency_id)
{
	return str_replace(",","", number_format(round($money,2),2));
}

/**
 * utf8字符转Unicode字符
 * @param string $char 要转换的单字符
 * @return void
 */
function utf8ToUnicode($char)
{
	switch(strlen($char))
	{
		case 1:
			return ord($char);
		case 2:
			$n = (ord($char[0]) & 0x3f) << 6;
			$n += ord($char[1]) & 0x3f;
			return $n;
		case 3:
			$n = (ord($char[0]) & 0x1f) << 12;
			$n += (ord($char[1]) & 0x3f) << 6;
			$n += ord($char[2]) & 0x3f;
			return $n;
		case 4:
			$n = (ord($char[0]) & 0x0f) << 18;
			$n += (ord($char[1]) & 0x3f) << 12;
			$n += (ord($char[2]) & 0x3f) << 6;
			$n += ord($char[3]) & 0x3f;
			return $n;
	}
}

/**
 * utf8字符串分隔为unicode字符串
 * @param string $str 要转换的字符串
 * @param string $pre
 * @return string
 */
function segmentToUnicode($str,$pre = '')
{
	$arr = array();
	$str_len = mb_strlen($str,'UTF-8');
	for($i = 0;$i < $str_len;$i++)
	{
		$s = mb_substr($str,$i,1,'UTF-8');
		if($s != ' ' && $s != '　')
		{
			$arr[] = $pre.'ux'.utf8ToUnicode($s);
		}
	}
	
	$arr = array_unique($arr);
	
	return implode(' ',$arr);
}

/**
 * 清除符号
 * @param string $str 要清除符号的字符串
 * @return string
 */
function clearSymbol($str)
{
	static $symbols = NULL;
	if($symbols === NULL)
	{
		$symbols = file_get_contents(getcwd().'/public/table/symbol.table');
		$symbols = explode("\r\n",$symbols);
	}
	return str_replace($symbols,"",$str);
}
?>